<div class="boxed">
    <div id="content-container">
        <div id="page-title">
           <h1 class="page-header text-overflow">Data Tables</h1>
            <div class="searchbox">
                <div class="input-group custom-search-form">
                    <input type="text" class="form-control" placeholder="Search..">
                    <span class="input-group-btn">
                        <button class="text-muted" type="button"><i class="demo-pli-magnifi-glass"></i></button>
                    </span>
                </div>
            </div>
        </div>
        <ol class="breadcrumb">
            <li><a href="{:url('Admin/Index/index')}">首页</a></li>
            <li>系统设置</li>
            <li class="active">菜单管理</li>
        </ol>
        <div id="page-content">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title"><button class="btn btn-info" onclick="add()">添加菜单</button></h3>
                </div>
                <div class="panel-body">
                    <table id="demo-dt-basic" class="table table-striped table-bordered" cellspacing="0" width="100%">
                        <thead>
                        <tr>
                            <th>权限名</th>
                            <th>权限</th>
                            <th class="min-tablet">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {foreach name="data" id="v"}
                            <tr>
                            <td>{$v['_name']}</td>
                            <td>{$v['name']}</td>
                            <td>
                                <a href="javascript:;" ruleId="{$v['id']}" onclick="add_child(this)">添加子权限</a> |
                                <a href="javascript:;" ruleId="{$v['id']}" ruleName="{$v['name']}" ruleTitle="{$v['title']}" onclick="edit(this)">修改</a> |
                                <a href="javascript:if(confirm('确定删除？'))location='{:url('Admin/Rule/delete',array('id'=>$v['id']))}'">删除</a>
                            </td>
                        </tr>
                        {/foreach}
                        </tbody>
                    </table>
                </div>
            </div>
            <!--===================================================-->
            <!-- End Striped Table -->

        </div>
    </div>
</div>
<div class="modal fade" id="thinkright-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    添加菜单
                </h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="{:url('Admin/Rule/add')}" method="post">
                    <div class="panel-body">
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="demo-hor-inputemail">权限名</label>
                            <div class="col-sm-9">
                                <input type="hidden" name="pid" value="0">
                                <input type="text"  id="demo-hor-inputemail" class="form-control" name="title" required="required">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="demo-hor-inputpass">权限</label>
                            <div class="col-sm-9">
                                <input type="text"  id="demo-hor-inputpass" class="form-control" name="name" required="required">
                                <span class="text-warning">输入模块/控制器/方法即可 例如 Admin/Rule/index</span>
                            </div>
                        </div>
                    </div>
                    <div class="panel-footer text-right">
                        <button class="btn btn-success" type="submit">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 修改菜单模态框开始 -->
<div class="modal fade" id="thinkright-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    修改权限
                </h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="{:url('Admin/Rule/edit')}" method="post">
                    <div class="panel-body">
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="demo-hor-inputemail">权限名</label>
                            <div class="col-sm-9">
                                <input type="hidden" name="id">
                                <input type="text"  id="demo-hor-inputemail" class="form-control" name="title" required="required">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label" for="demo-hor-inputpass">权限</label>
                            <div class="col-sm-9">
                                <input type="text"  id="demo-hor-inputpass" class="form-control" name="name" required="required">
                                <span class="text-danger">输入模块/控制器/方法即可 例如 Admin/Rule/index</span>
                            </div>
                        </div>
                    </div>
                    <div class="panel-footer text-right">
                        <button class="btn btn-success" type="submit">修改</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<!-- 修改菜单模态框结束 -->
<script type="text/javascript">
    /*添加权限*/
    function add(){
        $("input[name='title'],input[name='name']").val('');
        $("input[name='pid']").val(0);
        $('#thinkright-add').modal('show');
    }
    // 添加子菜单
    function add_child(obj){
        var ruleId=$(obj).attr('ruleId');
        $("input[name='pid']").val(ruleId);
        $("input[name='title']").val('');
        $("input[name='name']").val('');
        $('#thinkright-add').modal('show');
    }
    // 修改菜单
    function edit(obj){
        var ruleId=$(obj).attr('ruleId');
        var ruletitle=$(obj).attr('ruletitle');
        var ruleName=$(obj).attr('ruleName');
        $("input[name='id']").val(ruleId);
        $("input[name='title']").val(ruletitle);
        $("input[name='name']").val(ruleName);
        $('#thinkright-edit').modal('show');
    }
</script>